package com.hxkj.service.userCenter.impl;

import com.hxkj.client.service.SysNavigatesServiceClient;
import com.hxkj.domain.po.SysNavigates;
import com.hxkj.service.userCenter.SysNavigatesService;
import com.platform.common.domain.exception.CustomMessageException;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import com.platform.common.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class SysNavigatesServiceImpl implements SysNavigatesService{

    @Autowired
    private SysNavigatesServiceClient snsClient;

    @Override
    public void save(SysNavigates sysNavigates) throws Exception {
        if(StringUtils.isBlank(sysNavigates.getName())){
            throw new CustomMessageException("标签名称不能为空！");
        }
        if(StringUtils.isBlank(sysNavigates.getUrl())){
            throw new CustomMessageException("标签链接不能为空！");
        }
        ResultMessageStruct result = snsClient.save(sysNavigates);
        if(result.getCode() != 200){
            throw new CustomMessageException(result.getMessage());
        }
    }

    @Override
    public List<SysNavigates> select() throws Exception {
        ResultDataStruct<List<SysNavigates>> result = snsClient.select();
        if(result.getCode() != 200){
            throw new CustomMessageException(result.getMessage());
        }
        return result.getData();
    }

    @Override
    public void delete(SysNavigates sysNavigates) throws Exception {
        if(sysNavigates.getNavId() == null){
            throw new CustomMessageException("导航栏编号不能为空!");
        }
        ResultMessageStruct result = snsClient.delete(sysNavigates);
        if(result.getCode() != 200){
            throw new CustomMessageException(result.getMessage());
        }
    }

    @Override
    public void modify(SysNavigates sysNavigates) throws Exception {
        if(sysNavigates.getNavId() == null){
            throw new CustomMessageException("导航栏编号不能为空!");
        }
        if(StringUtils.isBlank(sysNavigates.getName())){
            throw new CustomMessageException("标签名称不能为空！");
        }
        if(StringUtils.isBlank(sysNavigates.getUrl())){
            throw new CustomMessageException("标签链接不能为空！");
        }
        ResultMessageStruct result = snsClient.modify(sysNavigates);
        if(result.getCode() != 200){
            throw new CustomMessageException(result.getMessage());
        }
    }

    @Override
    public void move(String navIds) throws Exception {
        if(StringUtils.isBlank(navIds)){
            throw new CustomMessageException("导航栏编号不能为空！");
        }
        ResultMessageStruct result = snsClient.move(navIds);
        if(result.getCode() != 200){
            throw new CustomMessageException(result.getMessage());
        }
    }
}
